#include <ConnectionBroker/clientconnection/ClientConnection.h>
#include <ConnectionBroker/Channels.h>
#include <json/json.h>

using namespace ConnectionBroker;

ClientConnection::ClientConnection()
: mAuthenticated(false)
{
}

ClientConnection::~ClientConnection()
{
}

void ClientConnection::subscribeTo(const std::vector<uint32_t>& channels)
{
   for(std::vector<uint32_t>::const_iterator it = channels.begin(); it != channels.end(); ++it)
   {
      uint32_t channel = *it;
      if(std::find(mChannels.begin(), mChannels.end(), channel) != mChannels.end())
         continue;

      mChannels.push_back(channel);
   }
}

void ClientConnection::unsubscribeFrom(const std::vector<uint32_t>& channels)
{
   for(std::vector<uint32_t>::const_iterator it = channels.begin(); it != channels.end(); ++it)
   {
      uint32_t channel = *it;
      std::vector<uint32_t>::iterator findIterator = std::find(mChannels.begin(), mChannels.end(), channel);
      if(findIterator == mChannels.end())
         continue;

      mChannels.erase(findIterator);
   }
}

bool ClientConnection::subscribedTo(const uint32_t channel)
{
   return channel < Channels::PREDEFINED_MAX || std::find(mChannels.begin(), mChannels.end(), channel) != mChannels.end();
}

